#include <iostream>
#include <stdio.h>
#include <cmath>
#include <string>
#include <algorithm>
#include <memory.h>

using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-6;
const double INF = 1e9 + 7;



int a[10];
void exchange(int a[], int begin, int end)
{
	int temp;
	while (begin<end)
	{
		temp = a[begin];
		a[begin] = a[end];
		a[end] = temp;
		begin++;
		end--;
	}

}

int main()
{
	freopen("data.in", "r", stdin);
	
	int m;
	memset(a, 0, 10);
	for (int i = 0; i < 10; i++)
	{
		cin >> a[i];
	}
	
	cin >> m;
	exchange(a,0,10-m-1);
	exchange(a, 10-m, 9);
	exchange(a, 0,9);

	int beginSum = 0;
	int endSum = 0;
	for (int i = 0; i < m; i++)
	{
		beginSum += a[i];

	}

	for (int j = 9; j >10 - m -1; j--)
	{
		endSum += a[j];
	}

	for (int i = 0; i < 9; i++)
	{
		cout << a[i] << " ";
	}
	cout <<a[9] << endl;
	cout << beginSum << " "<< endSum << endl;

	system("pause");
	return 0;
}